const whiteList = [
  "/root",
  "/rest/user/login",
  "/rest/user/reg",
  "/rest/user/login/company",
  "/rest/companys/create",
  "/rest/companys/update",
  "/companys/delete",
  "/rest/user/login/company",
  "/rest/user/login/company",
  "/rest/file/list",
]; //白名单列表
function WhiteList(originUrl, apiList) {
  const isWhiteList = (url) => {
    return url.includes("/images/") || whiteList.toString().includes(url);
  };
  const isLegal = (url) => {
    return url.includes("/images/") || apiList.toString().includes(url) || /\/rests\/json\/.*\//.test(url) //正则表达式形式进行拦截
  };

  if (isLegal(originUrl)) {
    if (isWhiteList(originUrl)) {
      console.log("[白名单接口]", originUrl);
      return 0; //白名单
    } else {
      console.log("[合法接口]", originUrl);
      return 1; //非白名单
    }
  } else {
    console.log("[非法连接]", originUrl);
    return 2; //非法连接
  }
}
module.exports = WhiteList;
